﻿using System;
using System.Reactive.Linq;
using Wulong.Phone.Dianping.Services;

namespace Wulong.Phone.Dianping.ViewModels
{
    public class ReviewDialogViewModel:DianpingViewModelBase
    {
        private bool _isBusy;
        public bool IsBusy
        {
            get { return _isBusy; }
            set
            {
                _isBusy = value;
                NotifyOfPropertyChange(() => IsBusy);
            }
        }
        private readonly IDisposable _disposable;
        public ReviewDialogViewModel(string link)
        {
            IsBusy = true;
            _disposable = DianpingService.ObservableFullReview(link)
                .ObserveOnDispatcher()
                .Finally(()=>IsBusy=false)
                .Subscribe(text =>
                               {
                                   FullReview = text;
                                   NotifyOfPropertyChange(()=>FullReview);
                               });
        }
        public string FullReview { get; set; }

        protected override void OnDeactivate(bool close)
        {
            base.OnDeactivate(close);
            if(_disposable!=null)
                _disposable.Dispose();
        }
    }
}
